/**
 * Created by mac on 2017/5/4.
 */

import java.io.*;
import java.security.*;

public class Skey_kb {
    public static void main(String args[]) throws Exception {
        FileInputStream f = getFileInputStream();
        ObjectInputStream b = getObjectInputStream(f);
        Key k = (Key) b.readObject();
        byte[] kb = k.getEncoded();
        FileOutputStream f2 = getFileOutputStream();
        f2.write(kb);
        // 打印密钥编码中的内容
        PrintOut(kb);
        System.out.println();
    }

    private static FileOutputStream getFileOutputStream() throws FileNotFoundException {
        return new FileOutputStream("keykb1.dat");
    }

    private static ObjectInputStream getObjectInputStream(FileInputStream f) throws IOException {
        return new ObjectInputStream(f);
    }

    private static FileInputStream getFileInputStream() throws FileNotFoundException {
        return new FileInputStream("key1.dat");
    }

    private static void PrintOut(byte[] kb) {
        for (int i = 0; i < kb.length; i++) {
            System.out.print(kb[i] + ",");
        }
    }
}
